package com.huawei.su;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Stack;

public class BM44 {
    public static void main(String[] args) {

    }

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     * @param s string字符串
     * @return bool布尔型
     */
    public boolean isValid (String s) {
        Map<Character, Character> map = new HashMap<>();
        map.put(']','[');
        map.put(')','(');
        map.put('}','{');

        Stack<Character> stack = new Stack<>();
        // write code here
        for (int i = 0; i < s.length(); i++) {
            char current = s.charAt(i);
            if(map.containsKey(current)){
                if(stack.isEmpty()){
                    return false;
                }
                if(Objects.equals(stack.pop(),map.get(current))){
                    continue;
                }else {
                    return false;
                }
            }else {
                stack.push(current);
            }
        }
        return stack.isEmpty();
    }
}
